package server;

import java.io.*;
import java.net.Socket;

public class ThreadServer extends Thread {
    private Socket socket;
    private BufferedReader in = null;
    private PrintWriter out = null;

    public ThreadServer(Socket socket) {
        this.socket = socket;
        try {
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(new BufferedOutputStream(socket.getOutputStream()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void run() {
        while (true) {
            try {
                String msgFromClient = in.readLine();
                System.out.println("我已经收到:" + msgFromClient);
                out.println("我已经收到:" + msgFromClient);
                out.flush();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }
    }

}
